package com.wl.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.module.EbComment;
import com.wl.eb.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(value="page",defaultValue = "1")int page) {

        System.out.println("=====进入CommentController的list方法,page："+page);

        Page commentPage=commentService.list(page);
        model.addAttribute("commentPage",commentPage);

        return "guestbook";
    }

    @PostMapping
    public String save(EbComment ebComment){
        System.out.println("=====productListRelativedCategory的save,ebComment"+ebComment);
        //1.调用service添加留言信息
        boolean result=commentService.save(ebComment);
        if (!result){
            throw new RuntimeException("添加留言失败！！");
        }
        //2.绑定数据到model，不需要返回数据
        //3.返回view


        return "redirect:comment/list";
    }
}
